#include <iostream>

#include "predictor_force.h"
#include "predictor_link.h"

using namespace std;

Predictor_force::Predictor_force( std::string id ) : Predictor_base( id )
{
  _string_type = "External force";
  // make predictor connections
  add_input_link( new Predictor_link( INPUT ) ); // force
  add_input_link( new Predictor_link( INPUT ) ); // mass
  add_input_link( new Predictor_link( OUTPUT ) ); // acceleration
  _predicted_inputs.resize( _input_links.size() );

  _complexity = 4.0;
}

Predictor_force::~Predictor_force()
{
}

void Predictor_force::save_state( float time )
{
  save_input( time );
}

void Predictor_force::predict( float )
{
//  cout << " # predictor_force: Predicting" << endl;
  _predicted_inputs[0] = _input_links[0]->get_value(); // force
  _predicted_inputs[1] = _input_links[1]->get_value(); // mass
  _predicted_inputs[2] = _input_links[0]->get_value() / _input_links[1]->get_value(); // a = F/m
}

void Predictor_force::activate_output_link( void )
{
  //cout << "activate_output_link" << endl;
  if(_active) {
    _output_link->activate();
  } else {
//    cout << "  " << _string_id << ":  De-activating output " << endl;
    _output_link->deactivate();
  }
}
